package com.gesis.persistence.imp;

import java.util.List;
import java.util.logging.Level;
import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.gesis.entity.GesTopic;
import com.gesis.persistence.EntityManagerHelper;
import com.gesis.persistence.IGesTopicDAO;

/**
 * A data access object (DAO) providing persistence and search support for
 * GesTopic entities. Transaction control of the save(), update() and delete()
 * operations must be handled externally by senders of these methods or must be
 * manually added to each of these methods for data to be persisted to the JPA
 * datastore.
 * 
 * @see com.gesis.entity.GesTopic
 * @author MyEclipse Persistence Tools
 */

public class GesTopicDAO implements IGesTopicDAO {
	// property constants
	public static final String TOP_START_DATE = "topStartDate";
	public static final String TOP_END_DATE = "topEndDate";
	public static final String TOP_NAME_TOPIC = "topNameTopic";
	public static final String TOP_P1 = "topP1";
	public static final String TOP_P2 = "topP2";
	public static final String TOP_P3 = "topP3";
	public static final String TOP_P4 = "topP4";
	public static final String TOP_P5 = "topP5";
	public static final String TOP_P6 = "topP6";
	public static final String TOP_P7 = "topP7";
	public static final String TOP_P8 = "topP8";
	public static final String TOP_P9 = "topP9";
	public static final String TOP_P10 = "topP10";
	public static final String TOP_P11 = "topP11";
	public static final String TOP_P12 = "topP12";
	public static final String TOP_P13 = "topP13";
	public static final String TOP_P14 = "topP14";
	public static final String TOP_P15 = "topP15";
	public static final String TOP_P16 = "topP16";
	public static final String TOP_P17 = "topP17";
	public static final String TOP_P18 = "topP18";
	public static final String TOP_P19 = "topP19";
	public static final String TOP_P20 = "topP20";
	public static final String TOP_P21 = "topP21";
	public static final String TOP_P22 = "topP22";
	public static final String TOP_P23 = "topP23";
	public static final String TOP_FORSCHUNG1 = "topForschung1";
	public static final String TOP_FORSCHUNG2 = "topForschung2";
	public static final String TOP_FORSCHUNG3 = "topForschung3";
	public static final String TOP_FORSCHUNG4 = "topForschung4";
	public static final String TOP_FORSCHUNG5 = "topForschung5";
	public static final String TOP_FORSCHUNG6 = "topForschung6";
	public static final String TOP_FORSCHUNG7 = "topForschung7";
	public static final String TOP_FORSCHUNG8 = "topForschung8";
	public static final String TOP_FORSCHUNG9 = "topForschung9";
	public static final String TOP_FORSCHUNG10 = "topForschung10";
	public static final String TOP_FORSCHUNG11 = "topForschung11";
	public static final String TOP_FORSCHUNG12 = "topForschung12";

	private EntityManager getEntityManager() {
		return EntityManagerHelper.getEntityManager();
	}

	/**
	 * Perform an initial save of a previously unsaved GesTopic entity. All
	 * subsequent persist actions of this entity should use the #update()
	 * method. This operation must be performed within the a database
	 * transaction context for the entity's data to be permanently saved to the
	 * persistence store, i.e., database. This method uses the
	 * {@link javax.persistence.EntityManager#persist(Object)
	 * EntityManager#persist} operation.
	 * 
	 * <pre>
	 * EntityManagerHelper.beginTransaction();
	 * GesTopicDAO.save(entity);
	 * EntityManagerHelper.commit();
	 * </pre>
	 * 
	 * @param entity
	 *            GesTopic entity to persist
	 * @throws RuntimeException
	 *             when the operation fails
	 */
	public void save(GesTopic entity) {
		EntityManagerHelper.log("saving GesTopic instance", Level.INFO, null);
		try {
			getEntityManager().persist(entity);
			EntityManagerHelper.log("save successful", Level.INFO, null);
		} catch (RuntimeException re) {
			EntityManagerHelper.log("save failed", Level.SEVERE, re);
			throw re;
		}
	}

	/**
	 * Delete a persistent GesTopic entity. This operation must be performed
	 * within the a database transaction context for the entity's data to be
	 * permanently deleted from the persistence store, i.e., database. This
	 * method uses the {@link javax.persistence.EntityManager#remove(Object)
	 * EntityManager#delete} operation.
	 * 
	 * <pre>
	 * EntityManagerHelper.beginTransaction();
	 * GesTopicDAO.delete(entity);
	 * EntityManagerHelper.commit();
	 * entity = null;
	 * </pre>
	 * 
	 * @param entity
	 *            GesTopic entity to delete
	 * @throws RuntimeException
	 *             when the operation fails
	 */
	public void delete(GesTopic entity) {
		EntityManagerHelper.log("deleting GesTopic instance", Level.INFO, null);
		try {
			entity = getEntityManager().getReference(GesTopic.class,
					entity.getTopKey());
			getEntityManager().remove(entity);
			EntityManagerHelper.log("delete successful", Level.INFO, null);
		} catch (RuntimeException re) {
			EntityManagerHelper.log("delete failed", Level.SEVERE, re);
			throw re;
		}
	}

	/**
	 * Persist a previously saved GesTopic entity and return it or a copy of it
	 * to the sender. A copy of the GesTopic entity parameter is returned when
	 * the JPA persistence mechanism has not previously been tracking the
	 * updated entity. This operation must be performed within the a database
	 * transaction context for the entity's data to be permanently saved to the
	 * persistence store, i.e., database. This method uses the
	 * {@link javax.persistence.EntityManager#merge(Object) EntityManager#merge}
	 * operation.
	 * 
	 * <pre>
	 * EntityManagerHelper.beginTransaction();
	 * entity = GesTopicDAO.update(entity);
	 * EntityManagerHelper.commit();
	 * </pre>
	 * 
	 * @param entity
	 *            GesTopic entity to update
	 * @return GesTopic the persisted GesTopic entity instance, may not be the
	 *         same
	 * @throws RuntimeException
	 *             if the operation fails
	 */
	public GesTopic update(GesTopic entity) {
		EntityManagerHelper.log("updating GesTopic instance", Level.INFO, null);
		try {
			GesTopic result = getEntityManager().merge(entity);
			EntityManagerHelper.log("update successful", Level.INFO, null);
			return result;
		} catch (RuntimeException re) {
			EntityManagerHelper.log("update failed", Level.SEVERE, re);
			throw re;
		}
	}

	public GesTopic findById(Long id) {
		EntityManagerHelper.log("finding GesTopic instance with id: " + id,
				Level.INFO, null);
		try {
			GesTopic instance = getEntityManager().find(GesTopic.class, id);
			return instance;
		} catch (RuntimeException re) {
			EntityManagerHelper.log("find failed", Level.SEVERE, re);
			throw re;
		}
	}

	/**
	 * Find all GesTopic entities with a specific property value.
	 * 
	 * @param propertyName
	 *            the name of the GesTopic property to query
	 * @param value
	 *            the property value to match
	 * @return List<GesTopic> found by query
	 */
	@SuppressWarnings("unchecked")
	public List<GesTopic> findByProperty(String propertyName, final Object value) {
		EntityManagerHelper.log("finding GesTopic instance with property: "
				+ propertyName + ", value: " + value, Level.INFO, null);
		try {
			final String queryString = "select model from GesTopic model where model."
					+ propertyName + "= :propertyValue";
			Query query = getEntityManager().createQuery(queryString);
			query.setParameter("propertyValue", value);
			return query.getResultList();
		} catch (RuntimeException re) {
			EntityManagerHelper.log("find by property name failed",
					Level.SEVERE, re);
			throw re;
		}
	}

	public List<GesTopic> findByTopStartDate(Object topStartDate) {
		return findByProperty(TOP_START_DATE, topStartDate);
	}

	public List<GesTopic> findByTopEndDate(Object topEndDate) {
		return findByProperty(TOP_END_DATE, topEndDate);
	}

	public List<GesTopic> findByTopNameTopic(Object topNameTopic) {
		return findByProperty(TOP_NAME_TOPIC, topNameTopic);
	}

	public List<GesTopic> findByTopP1(Object topP1) {
		return findByProperty(TOP_P1, topP1);
	}

	public List<GesTopic> findByTopP2(Object topP2) {
		return findByProperty(TOP_P2, topP2);
	}

	public List<GesTopic> findByTopP3(Object topP3) {
		return findByProperty(TOP_P3, topP3);
	}

	public List<GesTopic> findByTopP4(Object topP4) {
		return findByProperty(TOP_P4, topP4);
	}

	public List<GesTopic> findByTopP5(Object topP5) {
		return findByProperty(TOP_P5, topP5);
	}

	public List<GesTopic> findByTopP6(Object topP6) {
		return findByProperty(TOP_P6, topP6);
	}

	public List<GesTopic> findByTopP7(Object topP7) {
		return findByProperty(TOP_P7, topP7);
	}

	public List<GesTopic> findByTopP8(Object topP8) {
		return findByProperty(TOP_P8, topP8);
	}

	public List<GesTopic> findByTopP9(Object topP9) {
		return findByProperty(TOP_P9, topP9);
	}

	public List<GesTopic> findByTopP10(Object topP10) {
		return findByProperty(TOP_P10, topP10);
	}

	public List<GesTopic> findByTopP11(Object topP11) {
		return findByProperty(TOP_P11, topP11);
	}

	public List<GesTopic> findByTopP12(Object topP12) {
		return findByProperty(TOP_P12, topP12);
	}

	public List<GesTopic> findByTopP13(Object topP13) {
		return findByProperty(TOP_P13, topP13);
	}

	public List<GesTopic> findByTopP14(Object topP14) {
		return findByProperty(TOP_P14, topP14);
	}

	public List<GesTopic> findByTopP15(Object topP15) {
		return findByProperty(TOP_P15, topP15);
	}

	public List<GesTopic> findByTopP16(Object topP16) {
		return findByProperty(TOP_P16, topP16);
	}

	public List<GesTopic> findByTopP17(Object topP17) {
		return findByProperty(TOP_P17, topP17);
	}

	public List<GesTopic> findByTopP18(Object topP18) {
		return findByProperty(TOP_P18, topP18);
	}

	public List<GesTopic> findByTopP19(Object topP19) {
		return findByProperty(TOP_P19, topP19);
	}

	public List<GesTopic> findByTopP20(Object topP20) {
		return findByProperty(TOP_P20, topP20);
	}

	public List<GesTopic> findByTopP21(Object topP21) {
		return findByProperty(TOP_P21, topP21);
	}

	public List<GesTopic> findByTopP22(Object topP22) {
		return findByProperty(TOP_P22, topP22);
	}

	public List<GesTopic> findByTopP23(Object topP23) {
		return findByProperty(TOP_P23, topP23);
	}

	public List<GesTopic> findByTopForschung1(Object topForschung1) {
		return findByProperty(TOP_FORSCHUNG1, topForschung1);
	}

	public List<GesTopic> findByTopForschung2(Object topForschung2) {
		return findByProperty(TOP_FORSCHUNG2, topForschung2);
	}

	public List<GesTopic> findByTopForschung3(Object topForschung3) {
		return findByProperty(TOP_FORSCHUNG3, topForschung3);
	}

	public List<GesTopic> findByTopForschung4(Object topForschung4) {
		return findByProperty(TOP_FORSCHUNG4, topForschung4);
	}

	public List<GesTopic> findByTopForschung5(Object topForschung5) {
		return findByProperty(TOP_FORSCHUNG5, topForschung5);
	}

	public List<GesTopic> findByTopForschung6(Object topForschung6) {
		return findByProperty(TOP_FORSCHUNG6, topForschung6);
	}

	public List<GesTopic> findByTopForschung7(Object topForschung7) {
		return findByProperty(TOP_FORSCHUNG7, topForschung7);
	}

	public List<GesTopic> findByTopForschung8(Object topForschung8) {
		return findByProperty(TOP_FORSCHUNG8, topForschung8);
	}

	public List<GesTopic> findByTopForschung9(Object topForschung9) {
		return findByProperty(TOP_FORSCHUNG9, topForschung9);
	}

	public List<GesTopic> findByTopForschung10(Object topForschung10) {
		return findByProperty(TOP_FORSCHUNG10, topForschung10);
	}

	public List<GesTopic> findByTopForschung11(Object topForschung11) {
		return findByProperty(TOP_FORSCHUNG11, topForschung11);
	}

	public List<GesTopic> findByTopForschung12(Object topForschung12) {
		return findByProperty(TOP_FORSCHUNG12, topForschung12);
	}

	/**
	 * Find all GesTopic entities.
	 * 
	 * @return List<GesTopic> all GesTopic entities
	 */
	@SuppressWarnings("unchecked")
	public List<GesTopic> findAll() {
		EntityManagerHelper.log("finding all GesTopic instances", Level.INFO,
				null);
		try {
			final String queryString = "select model from GesTopic model";
			Query query = getEntityManager().createQuery(queryString);
			return query.getResultList();
		} catch (RuntimeException re) {
			EntityManagerHelper.log("find all failed", Level.SEVERE, re);
			throw re;
		}
	}

}